package cn.lg.soar.common.util;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Date;

/**
 * @author luguoxiang 469599794@qq.com
 * @Date: 2023/11/20 11:10
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
public interface FormatUtils {

    IFormatter.DateFormatter DATE_FORMATTER = new IFormatter.DateFormatter("yyyy-MM-dd HH:mm:ss");
    IFormatter.LocalDateTimeFormatter LOCAL_DATETIME_FORMATTER = new IFormatter.LocalDateTimeFormatter("yyyy-MM-dd HH:mm:ss");
    IFormatter.LocalDateFormatter LOCAL_DATE_FORMATTER = new IFormatter.LocalDateFormatter("yyyy-MM-dd");
    IFormatter.LocalTimeFormatter LOCAL_TIME_FORMATTER = new IFormatter.LocalTimeFormatter("HH:mm:ss");
    IFormatter.NumberFormatter NUMBER_FORMATTER = new IFormatter.NumberFormatter(",###.00");

    static String format(Number value) {
        return NUMBER_FORMATTER.format(value);
    }
    static String format(Number value, String def) {
        return NUMBER_FORMATTER.format(value, def);
    }

    static String format(LocalDateTime value) {
        return LOCAL_DATETIME_FORMATTER.format(value);
    }
    static String format(LocalDateTime value, String def) {
        return LOCAL_DATETIME_FORMATTER.format(value, def);
    }

    static String format(LocalDate value) {
        return LOCAL_DATE_FORMATTER.format(value);
    }
    static String format(LocalDate value, String def) {
        return LOCAL_DATE_FORMATTER.format(value, def);
    }

    static String format(LocalTime value) {
        return LOCAL_TIME_FORMATTER.format(value);
    }
    static String format(LocalTime value, String def) {
        return LOCAL_TIME_FORMATTER.format(value, def);
    }

    static String format(Date value) {
        return DATE_FORMATTER.format(value);
    }
    static String format(Date value, String def) {
        return DATE_FORMATTER.format(value, def);
    }

    static Number parseNumber(String source) {
        return NUMBER_FORMATTER.parse(source);
    }
    static Number parseNumber(String source, Number def) {
        return NUMBER_FORMATTER.parse(source, def);
    }

    static Date parseDate(String source) {
        return DATE_FORMATTER.parse(source);
    }
    static Date parseDate(String source, Date def) {
        return DATE_FORMATTER.parse(source, def);
    }

    static LocalDateTime parseLocalDateTime(String source) {
        return LOCAL_DATETIME_FORMATTER.parse(source);
    }
    static LocalDateTime parseLocalDateTime(String source, LocalDateTime def) {
        return LOCAL_DATETIME_FORMATTER.parse(source, def);
    }

    static LocalDate parseLocalDate(String source) {
        return LOCAL_DATE_FORMATTER.parse(source);
    }
    static LocalDate parseLocalDate(String source, LocalDate def) {
        return LOCAL_DATE_FORMATTER.parse(source, def);
    }

    static LocalTime parseLocalTime(String source) {
        return LOCAL_TIME_FORMATTER.parse(source);
    }
    static LocalTime parseLocalTime(String source, LocalTime def) {
        return LOCAL_TIME_FORMATTER.parse(source, def);
    }

}
